#Responsability:
#Logging initialization

library(logging)

Logging <- setRefClass(    
  "logging"
  
  , fields = list(
      logPath="character",
      logFile="character"
    )
  , methods = list(
    #
    #
    # Constructor
    #
    #
    initialize = function(..., logPath=configuration@commonFolder,
                            logFile=configuration@logFile)
    {
      callSuper(..., logPath=logPath,
                logFile=logFile)
      logIni()
    },
    #
    #
    # Initialize logging
    #
    #
    logIni = function() {
#       basicConfig()
#       
#       ls(getLogger())
#       with(getLogger(), level)
#       with(getLogger(), names(handlers))
#       loginfo('Start logging property')
#       #logwarn('%s %d', 'my name is', 5)
#       #logdebug('I am a silent child')
#       
#       
#       
#       addHandler(writeToFile, logger="company", file="sample.log")
#       with(getLogger(), names(handlers))
#       #loginfo('test')
#       #logwarn('test')
#       #    removeHandler('writeToConsole')
#       #logwarn('test')
#       
#       addHandler(writeToConsole)
#       setLevel(30, getHandler('basic.stdout'))
#       #loginfo('test')
#       #logwarn('test')
#       with(getHandler('basic.stdout'), level)
#       
#       
      logReset()
      
      file <- paste(logPath,logFile,sep="")
      print(file)
      basicConfig(level='FINEST')
      addHandler(writeToFile, file=file, level='DEBUG')
      with(getLogger(), names(handlers))
      loginfo('test %d', 1)
      logdebug('test %d', 2)
      logwarn('test %d', 3)
      logfinest('test %d', 4)
      
    },
    testLogging = function(text) {
      loginfo(text)
    }

  )
)
# 
# log <- Logging()
# 
# log$testLogging("prueba")
#loginfo("prueba2")
